/**
 * 
 */
package neptune.manager.validator.core;

import neptune.manager.builder.IPAddressRange;
import neptune.manager.model.topology.NetworkInterface;
import neptune.manager.model.topology.Node;
import neptune.manager.utils.Logger.MessageType;
import neptune.manager.validator.Validator;
import neptune.manager.validator.ValidatorResult;
import neptune.manager.validator.rules.node.ControlPortRule;
import neptune.manager.validator.rules.node.HdDefinitionRule;
import neptune.manager.validator.rules.node.NetInterfaceNameUniquenessRule;
import neptune.manager.validator.rules.node.OperativeSystemRule;
import neptune.manager.validator.rules.node.RamDefinitionRule;
import neptune.manager.validator.rules.node.SoftwareTemplateDefinitionRule;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class CoreNodeValidator extends Validator<Node> {

	protected Validator<NetworkInterface> validator;

	public CoreNodeValidator(IPAddressRange controlIpRange) {
		addRule(new ControlPortRule());
		addRule(new HdDefinitionRule());
		addRule(new OperativeSystemRule());
		addRule(new RamDefinitionRule());
		addRule(new NetInterfaceNameUniquenessRule());
		addRule(new SoftwareTemplateDefinitionRule());

		validator = new CoreNetInterfaceValidator(controlIpRange);
	}

	@Override
	public String getName() {
		return "CoreNodeValidator";
	}

	@Override
	protected ValidatorResult validationAlgorithm(Node toValidate,
			ValidatorResult result) {

		result.getLog().addMessage(
				"Validating node '" + toValidate.getId() + "'",
				MessageType.NORMAL);

		for (NetworkInterface netIf : toValidate.getInterfaces()) {
			validator.validate(netIf, result);
		}

		return result;
	}

	public CoreNetInterfaceValidator getNetIfValidator() {
		return (CoreNetInterfaceValidator) validator;
	}
}
